package com.xr.miniprogram.tools;

import com.xr.miniprogram.domain.MiniProgramOrder;
import com.xr.miniprogram.service.IMiniProgramOrderService;
import com.xr.miniprogram.service.WXPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 微信支付定时器
 */
@Slf4j
@Component
public class WxPayTask {
    @Resource
    private IMiniProgramOrderService orderService;

    @Resource
    private WXPayService wxPayService;
    /**
     * 每天凌晨两点执行一次。查询超过10分钟未支付的订单
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void orderConfirm() throws Exception {
        List<MiniProgramOrder> miniProgramOrders = orderService.getNoPay(10);
        for (MiniProgramOrder miniProgramOrder : miniProgramOrders) {
            String orderNo = miniProgramOrder.getOrderNumber();
            log.info("查询到了超时订单==>{}",orderNo);
            wxPayService.checkOrderStatus(orderNo);
        }
    }
}
